package com.wbdgj.ui.word_compaign;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.RelativeLayout;

import com.google.gson.internal.LinkedTreeMap;
import com.wbdgj.R;
import com.wbdgj.adapter.CouponWordCompaignAdapter;
import com.wbdgj.adapter.WordCompaignAdapter;
import com.wbdgj.base.BaseApplication;

import java.text.DecimalFormat;
import java.util.List;

public class CouponWordCompaignDialogActivity extends Activity{

    private Context context = this;

    private GridView roomGrid;
    private CouponWordCompaignAdapter wordCompaignAdapter;
    private List<LinkedTreeMap> linkedTreeMaps;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ui_word_compaign_dialog);
        getWindow().getAttributes().width = RelativeLayout.LayoutParams.MATCH_PARENT;
        getWindow().getAttributes().gravity = Gravity.BOTTOM;
        linkedTreeMaps = BaseApplication.getInstance().getlinkedTreeMapList();
        roomGrid = findViewById(R.id.roomGrid);
        findViewById(R.id.closeImg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        wordCompaignAdapter = new CouponWordCompaignAdapter(context, linkedTreeMaps);
        roomGrid.setAdapter(wordCompaignAdapter);

        roomGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                if(!wordCompaignAdapter.hasNoData){
                    startActivityForResult(new Intent(context, WordTatterActivity.class)
                            .putExtra("rule_code", wordCompaignAdapter.getItem(i).get("rule_code")+"")
                            .putExtra("rule_title", wordCompaignAdapter.getItem(i).get("rule_title")+"") , 1);
                }


            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1 & resultCode == 2){
            setResult(1);
            finish();
        }
    }
}
